/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package evaluationtestsuits;

import dao.Users;
import dao.IdentificationType;
import dao.Users;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

/**
 *
 * @author Diego
 */
public class UserFunctions{

    public static void CreateUser() {
        Users u = new Users();
        u.setActive(Boolean.TRUE);
        u.setIdentificationNumber(new Long(getRandomNumber()));
        u.setIdentificationType(IdentificationType.NATIONAL_IDENTIFICATION);
        u.setName("NamebyUser1");
        u.setSurname("SurmanebyUser1");
        u.setUserName("UsernamebyUser1");
        u.setUserPassword("PasswordbyUser1");
        create(u);
    }

    public static void testEditUser() {
        Users u_updated = new Users();
        u_updated.setActive(Boolean.TRUE);
        u_updated.setId(new Long("1"));
        u_updated.setIdentificationNumber(new Long(getRandomNumber()));
        u_updated.setIdentificationType(IdentificationType.NATIONAL_IDENTIFICATION);
        u_updated.setName("NamebyUser1");
        u_updated.setSurname("SurmanebyUser1");
        u_updated.setUserName("UsernamebyUser1");
        u_updated.setUserPassword("PasswordbyUser1");
        edit(u_updated);
    }

    public static void testFindById() {
        Users find = find(new Long("1"));
        System.out.println("Users Name: " + find.getName() + " Surmane: " + find.getSurname());
    }

    public static void testFindAllUsers() {
        List<Users> AllUsers = findAll();
        Iterator<Users> iterator = AllUsers.iterator();
        while (iterator.hasNext()) {
//            iterator.next();
            Users usr = iterator.next();
            System.out.println("Users Name: " + usr.getName() + " ID: " + usr.getId());
        }
    }
    
    public static void testDeleteUser() {
        Users find = find(new Long("103"));
        remove(find);
        
    }
    
    private static String getRandomNumber(){
        Random rnd = new Random();
        int n = 10000000 + rnd.nextInt(90000000);
        return ""+n;
    }

    private static void create(dao.Users user) {
        dao.UsersFacadeWS service = new dao.UsersFacadeWS();
        dao.UsersFacade port = service.getUsersFacadePort();
        port.create(user);
    }

    private static java.util.List<dao.Users> findAll() {
        dao.UsersFacadeWS service = new dao.UsersFacadeWS();
        dao.UsersFacade port = service.getUsersFacadePort();
        return port.findAll();
    }

    private static Users find(java.lang.Object arg0) {
        dao.UsersFacadeWS service = new dao.UsersFacadeWS();
        dao.UsersFacade port = service.getUsersFacadePort();
        return port.find(arg0);
    }

    private static void remove(dao.Users arg0) {
        dao.UsersFacadeWS service = new dao.UsersFacadeWS();
        dao.UsersFacade port = service.getUsersFacadePort();
        port.remove(arg0);
    }

    private static void edit(dao.Users arg0) {
        dao.UsersFacadeWS service = new dao.UsersFacadeWS();
        dao.UsersFacade port = service.getUsersFacadePort();
        port.edit(arg0);
    }
}
